package com.shchuangzhi.smartguard;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.AttributeSet;

import com.elvishew.xlog.XLog;
import com.shchuangzhi.smartguard.core.Consts;
import com.shchuangzhi.smartguard.core.DBHelper;
import com.shchuangzhi.smartguard.core.SyncRecord;

/**
 * Created by j_hu on 5/4/17.
 */

public class LogoutPreference extends YesOrNoPreference {
    public LogoutPreference(Context ctx, AttributeSet attrs) {
        super(ctx, attrs);
    }

    @Override
    protected void OnNegativeButtonClick(Context ctx) {

    }

    @Override
    protected void OnPositiveButtonClick(Context ctx) {
        SharedPreferences sp = ctx.getSharedPreferences(Consts.APP_FULL_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean(Consts.PREF_KEY_LOGIN_AUTO, false);
        editor.commit();
        SyncRecord.getInstance().empty();
        Activity activity = ActivityManager.getInstance().getCurrentActivity();
        Intent intent = new Intent(activity, LoginActivity.class);
        activity.startActivity(intent);
        activity.finish();
    }
}
